package com.wf.mock.app.utils;

import java.util.UUID;

import org.apache.commons.lang3.StringUtils;

import com.alibaba.fastjson.JSONObject;

public final class MinaUtils {

	private MinaUtils() {
	}

	public static final String MSGSPLITTER = "\b";

	public static String wrapMsg4App(String msg) {

		return msg.endsWith(MSGSPLITTER) ? msg : msg + MSGSPLITTER;
	}
	
	public static String generateUUID() {
		return UUID.randomUUID().toString().replace("-", "");
	}
	
	
	/**
	 * 获取一条信息的最大长度
	 * 
	 * @return
	 */
	public static int getMsgMaxLength() {
		return Math.abs(Math.round((10000 - 2000) / 3));
	}
	
	
	public static void inject2ContentTime(JSONObject json) {
		String content = json.getString("content");
		if (StringUtils.isNoneBlank(content)) {
			json.put("content", content + "@@" + System.currentTimeMillis());
		}
	}

	public static long parseCostTime(JSONObject json) {
		String content = json.getString("content");
		if (StringUtils.isNoneBlank(content) && content.contains("@@")) {
			long startTime = Long.parseLong(content.split("@@")[1]);
			return System.currentTimeMillis() - startTime;
		}
		return 0L;
	}
}
